﻿@model ToQueryString.Models.HomeIndexViewModel

@{
    ViewBag.Title = "Serialize object into QueryString";
}

<!DOCTYPE html>
<html>
    <head>
	    <meta charset="utf-8" />
        <title>@ViewBag.Title</title>
    </head>
    <body>
        
        <h1>@ViewBag.Title</h1>
        
        <h2>Request class</h2>
        
        <pre>
public class WebServiceRequest
{
    public string text { get; set; }
    public double number { get; set; }
    public int integer { get; set; }
    public bool truthiness { get; set; }
    public string dontinclude;
    public string[] array { get; set; }
    public List&lt;int&gt; collection { get; set; }
}
</pre>

        <h2>Example request object</h2>
        
<pre>
new WebServiceRequest()
{
    text = "Hello World!",
    number = 42.69,
    integer = 50,
    truthiness = false,
    dontinclude = "notincluded",
    array = new[] {"bar", "disco"},
    collection = new List&lt;int&gt;() {1, 2, 3, 5, 8, 13, 21, 34}
};
</pre>

        <h2>Example request object as QueryString</h2>

        <pre>@Model.RequestAsQueryString</pre>
        
        <h3>QueryString inserted into a URI</h3>

        <pre>http://domain.com/webservice?@Model.RequestAsQueryString</pre>
        
        <h2>Example request object as JSON</h2>

        <pre id="uiRequestAsJson"></pre>

        <script>
            var json = @Html.Raw(Model.RequestAsJson);
            var jsonString = JSON.stringify(json, null, 4);
            var uiRequestAsJson = document.getElementById('uiRequestAsJson');
            uiRequestAsJson.innerHTML = jsonString;
        </script>
        
    </body>
</html>